import 'package:shared_preferences/shared_preferences.dart';

class SPUtils {
  //token
  static const String TOKEN = "token";

  //用户名
  static const String USER_NAME = "user_name";

  //用户头像
  static const String USER_ICON = "user_icon";

  //用户手机号
  static const String USER_PHONE = "user_phone";

  //用户手机号
  static const String USER_PASSWORD = "user_password";

  //是否记住密码
  static const String IS_REMEMBER_PASSWORD = "is_remember_password";

  //公司id
  static const String COMPANY_ID = "company_id";

  //公司名称
  static const String COMPANY_NAME = "company_name";

  //公司余额
  static const String COMPANY_AMOUNT = "company_amount";

  //是不是公司管理员
  static const String IS_ADMIN = "is_admin";

  //搜索公司历史记录
  static const SEARCH_COMPANY_HISTORY_RECORD = "search_company_history_record";

  //搜索账户历史记录
  static const SEARCH_ACCOUNT_HISTORY_RECORD = "search_account_history_record";

  //搜索账户管理历史记录
  static const SEARCH_ACCOUNT_MANAGE_HISTORY_RECORD = "search_account_manage_history_record";

  //搜索交易流水历史记录
  static const SEARCH_TRANSACTION_FLOW_HISTORY_RECORD = "search_transaction_flow_history_record";

  //搜索车辆历史记录
  static const SEARCH_VEHICLE_HISTORY_RECORD = "search_vehicle_history_record";

  //搜索司机历史记录
  static const SEARCH_DRIVER_HISTORY_RECORD = "search_driver_history_record";

  //快速划拨权限
  static const String PERMISSION_TRANSFER_COMPANY = "permission_transfer_company";

  //车队账户划拨权限
  static const String PERMISSION_TRANSFER_MOTORCADE = "permission_transfer_motorcade";

  //卡账户划拨权限
  static const String PERMISSION_TRANSFER_CARD = "permission_transfer_card";

  static saveInt(String key, int value) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    sp.setInt(key, value);
  }

  static saveString(String key, String value) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    sp.setString(key, value);
  }

  static saveBool(String key, bool value) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    sp.setBool(key, value);
  }

  static saveDouble(String key, double value) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    sp.setDouble(key, value);
  }

  static saveStringList(String key, List<String> value) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    sp.setStringList(key, value);
  }

  static Future<int> getInt(String key, {int defaultValue = 0}) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    return sp.getInt(key) ?? defaultValue;
  }

  static Future<String> getString(String key, {String defaultValue = ""}) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    return sp.getString(key) ?? defaultValue;
  }

  static Future<bool> getBool(String key, {bool defaultValue = false}) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    return sp.getBool(key) ?? defaultValue;
  }

  static Future<double> getDouble(String key, {double defaultValue = 0.0}) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    return sp.getDouble(key) ?? defaultValue;
  }

  static Future<List<String>> getStringList(String key) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    return sp.getStringList(key) ?? [];
  }

  static clear() async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    sp.clear();
  }
}
